package com.zjl.springbatch.job.listener;

import com.zjl.springbatch.util.OutColour;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobExecutionListener;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.stereotype.Service;

//统计时间
@Service
public class DBToDBJobListener implements JobExecutionListener {

    @Override
    public void beforeJob(JobExecution jobExecution) {
        long begin = System.currentTimeMillis();
        OutColour.out.printlnRed("**********************【DBToDBJobListener 开始时间】" + begin + "************************");
        ExecutionContext executionContext = jobExecution.getExecutionContext();
        //获取执行的当前时间
        executionContext.putLong("begin",System.currentTimeMillis());

    }

    @Override
    public void afterJob(JobExecution jobExecution) {
        long end = System.currentTimeMillis();
        ExecutionContext executionContext = jobExecution.getExecutionContext();
        long begin = executionContext.getLong("begin");

        System.out.println("总时间：" + (end-begin));
        OutColour.out.printlnRed("**********************【DBToDBJobListener 开始时间】" + end + "************************");
        OutColour.out.printlnRed("**********************【DBToDBJobListener 总耗时间】" + (end-begin) + "************************");

    }
}
